<?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateItemsTable extends Migration {

	/**
	 * Run the migrations.
	 *
	 * @return void
	 */
	public function up()
	{
		Schema::create('items', function($table){
			$table->increments('pk');
			$table->string('reference');
			$table->string('name');
			$table->integer('created_by_fk')->unsigned();
			$table->integer('located_at_fk')->unsigned();
			$table->double('price', 15, 8)->unsigned();
			$table->integer('amount')->unsigned();
			$table->string('image_url');
			$table->timestamps();
		});

		Schema::table('items', function($table){
			$table->foreign('located_at_fk')->references('pk')->on('item_locations');
		});
	}

	/**
	 * Reverse the migrations.
	 *
	 * @return void
	 */
	public function down()
	{
		Schema::table('items', function($table){
			$table->dropForeign('items_located_at_fk_foreign');
		});
		echo "items table relationships removed\n";
		Schema::drop('items');
		echo "items table deleted\n";
	}

}
